<!--
 * @Author: 汪军 624473119@qq.com
 * @Date: 2023-10-10 17:21:51
 * @LastEditors: 汪军 624473119@qq.com
 * @LastEditTime: 2023-12-12 15:38:20
 * @FilePath: \ekee-web\src\views\end\my-refund\MyRefund.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
  <div class="shoppingCart relative h100">
    <div class="container overflow-y">
      <div class="easy-out-manage">
        <EnterpriseCenterTitle :titleList="titleList"></EnterpriseCenterTitle>
        <div class="mt4 px4"></div>
        <div v-if="cartList.length">
          <div class="carr_num">购物车（全部{{ cartList.length }}）</div>
          <div class="cart_list">
            <el-checkbox
              v-model="checkAll"
              :indeterminate="isIndeterminate"
              @change="handleCheckAllChange">全选
            </el-checkbox>
            <el-button
              @click="allCartListDelete"
              style="
                height: 42px;
                background: #f0ae3c;
                border-radius: 8px 8px 8px 8px;
                opacity: 1;
                font-size: 14px;
                font-family: PingFang SC-Medium, PingFang SC;
                font-weight: 500;
                color: #ffffff;
                margin-left: 15px;
                margin-top: -5px;
              "
              >删除</el-button
            >
  
            <el-checkbox-group
              v-model="checkedCities"
              @change="handleCheckedCitiesChange"
              class="el_checkbox_group"
            >
              <el-checkbox
                class="el_checkbox"
                v-for="(item, index) in cartList"
                :key="index"
                :label="item.id"
              >
                <div class="cartList_info">
                  <div class="cartList_info_tittle">
                    来源企业：{{ item.company }}
                  </div>
                  <div class="cartList_info_list">
                    <div class="cart_img">
                      <img :src="item.image" alt="" />
                      <img
                        v-if="item.is_canceled == 2"
                        class="xiajia"
                        src="../../../assets/images/xiajia.png"
                        alt=""
                      />
                    </div>
  
                    <div class="cart_info_content">
                      <div class="cart_info_content_tittle">
                        <span class="tittle">{{ item.name }}</span>
                        <span style="margin-top: 5px">{{ item.category }}</span>
                      </div>
                      <div class="cart_info_content_pruice">
                        <span>单价</span>
                        <span style="margin-top: 54px"
                          >{{ item.price }}易链值</span
                        >
                      </div>
                      <div class="cart_info_content_num">
                        <span>数量</span>
                        <div @click.stop style="margin-top: 10px">
                          <el-input-number
                            v-model="item.quantity"
                            :min="1"
                            :max="999999"
                            @change="handleChange($event, item)"
                            @click.prevent
                          />
                        </div>
                        <span style="margin-top: 13px"
                          >最小起换量：{{ item.min_sales_quantity }}</span
                        >
                      </div>
                    </div>
                    <div class="cart_button">
                      <el-button
                        @click="deleteCartInfo(item.id)"
                        style="
                          height: 42px;
                          background: #f0ae3c;
                          border-radius: 8px 8px 8px 8px;
                          opacity: 1;
                          font-size: 14px;
                          font-family: PingFang SC-Medium, PingFang SC;
                          font-weight: 500;
                          color: #ffffff;
                        "
                        >删除
                      </el-button>
                      <div
                        :class="item.is_canceled==2 ? 'onbuyOnce' : 'buyOnce' "
                        @click="buyImmediately(item)"
                        >立即易定</div
                      >
                    </div>
                  </div>
                </div>
              </el-checkbox>
            </el-checkbox-group>
          </div>
          <div class="carr_numBuy">
            <div class="all_money">合计:{{ cartListTotalPrice }}</div>
            <el-button
              style="
                height: 42px;
                background: #f0ae3c;
                border-radius: 8px 8px 8px 8px;
                opacity: 1;
                font-size: 14px;
                font-family: PingFang SC-Medium, PingFang SC;
                font-weight: 500;
                color: #ffffff;
              "
              @click="buyGoods"
              >结算</el-button
            >
          </div>
        </div>
        <!-- 暂无数据 -->
        <Empty v-else></Empty>
      </div>
    </div>
    <!-- 分页 -->
    <TablePagination v-if="totalList > 0" :totalList="totalList" :page="cartIndexPage.page" @handleCurrentChange="handleCurrentChange"></TablePagination>
    <!-- 立即易定弹框 -->
    <el-dialog
      v-model="centerDialogVisible"
      width="40%"
      align-center
      center
      class="el_ydDialog"
    >
      <div class="centerDialogVisible_footer">
        <div class="tittle">立即易定</div>
        <div
          :class="
            chain_money > 0
              ? 'centerDialogVisible_footer_btn'
              : 'centerDialogVisible_footer_btnTwo'
          "
          @click="onBuyCenterDialogVisible"
        >
          <div>{{ chain_money }}</div>
          <div>用易链值兑换</div>
        </div>
        <div
          :class="
            available_money > 0
              ? 'centerDialogVisible_footer_btn'
              : 'centerDialogVisible_footer_btnTwo'
          "
          @click="yiEDuBuyCenterDialogVisible"
        >
          <div>{{ available_money }}</div>
          <div>用先易额度兑换</div>
        </div>
      </div>
    </el-dialog>
    <!-- 使用易链接值支付 -->
    <el-dialog
      v-model="yEDuDialogVisible"
      width="40%"
      align-center
      center
      class="el_ydDialog"
    >
      <div
        class="centerDialogVisibleYlian_footer"
        v-if="chain_money >= orderPay.money"
      >
        <div class="centerDialogVisibleYlian_footer_yed">
          本次易定花费
          <span style="color: #2487e8">{{ orderPay.money }}</span> 易链值
        </div>

        <div
          class="centerDialogVisibleYlian_footer_yed"
          style="margin-top: 30px"
        >
          是否易定？
        </div>

        <div class="centerDialogVisibleYlian_footer_btnTwo">
          <el-button
            @click="yEDuDialogVisible = false"
            style="
              width: 178px;
              height: 48px;
              background: rgba(0, 82, 217, 0.12);
              border-radius: 90px 90px 90px 90px;
              opacity: 1;
            "
            round
            >取消</el-button
          >
          <el-button
            @click="YLbuy"
            type="primary"
            style="
              width: 178px;
              height: 48px;
              background: #2487e8;
              border-radius: 90px 90px 90px 90px;
              opacity: 1;
            "
            round
            >确认</el-button
          >
        </div>
      </div>
      <div
        class="centerDialogVisibleYlian_footer"
        v-if="chain_money < orderPay.money"
      >
        <div class="centerDialogVisibleYlian_footer_yed">
          本次易定花费
          <span style="color: #2487e8">{{ orderPay.money }}</span> 易链值
        </div>

        <div
          class="centerDialogVisibleYlian_footer_yed"
          style="margin-top: 30px"
        >
          您的易链值不足，无法易定
        </div>

        <div class="centerDialogVisibleYlian_footer_btnTwo">
          <el-button
            @click="yEDuDialogVisible = false"
            type="primary"
            style="
              width: 178px;
              height: 48px;
              background: #2487e8;
              border-radius: 90px 90px 90px 90px;
              opacity: 1;
            "
            round
            >知道了</el-button
          >
        </div>
      </div>
    </el-dialog>
    <!-- 使用先易额度 -->
    <el-dialog
      v-model="centerDialogVisibleYlian"
      width="40%"
      align-center
      center
      class="el_ydDialogBuy"
    >
      <div class="centerDialogVisibleYlian_footer" v-if="available_money == 0">
        <div class="centerDialogVisibleYlian_footer_btn">
          您还没有先易额度，是否联系担保公司为您担保?
        </div>
        <div class="centerDialogVisibleYlian_footer_danbao">
          小提示:您点击“确定联系”后，担保公司会与您联系，进行资信评估，资信评估通过后，担保公司会为您拨发相应的先易额度，您可使用先易额度易定别人的商品。
        </div>
        <div class="centerDialogVisibleYlian_footer_hetong">
          <span>您可以在线查看《易链值借贷合同》模板</span>
          <el-button
            type="primary"
            style="
              width: 88px;
              height: 36px;
              background: #2487e8;
              border-radius: 10px 10px 10px 10px;
              margin-left: 10px;
            "
            >点击查看</el-button
          >
        </div>
        <div
          class="centerDialogVisibleYlian_footer_hetong"
          style="margin: 20px 0"
        >
          <span>您想要担保的金额是：</span>
          <el-input v-model="danbaoJe" placeholder="请输入金额" />元
        </div>
        <div class="centerDialogVisibleYlian_footer_btnTwo">
          <el-button
            @click="yilianQuxiao"
            style="
              width: 178px;
              height: 48px;
              background: rgba(0, 82, 217, 0.12);
              border-radius: 90px 90px 90px 90px;
              opacity: 1;
            "
            round
            >取消</el-button
          >
          <el-button
            @click="onQueRen"
            type="primary"
            style="
              width: 178px;
              height: 48px;
              background: #2487e8;
              border-radius: 90px 90px 90px 90px;
              opacity: 1;
            "
            round
            >确认联系</el-button
          >
        </div>
      </div>
      <div
        class="centerDialogVisibleYlian_footer"
        v-else-if="available_money > orderPay.money"
      >
        <div class="centerDialogVisibleYlian_footer_yed">
          本次易定花费
          <span style="color: #2487e8">{{ orderPay.money }}</span> 先易额度
        </div>
        <div class="centerDialogVisibleYlian_footer_danbao">
          <div class="yedJs">
            本次易定价值 <span style="color: #18bc9f">{{ orderPay.money }}</span
            >先易额度
          </div>
          <div class="yedJs">
            您还需要付费
            <span style="color: #18bc9f">
              {{ orderPay.money * guarantee_fee_ratio * 0.01 }}</span
            >
            元人民币给易可易平台（{{ guarantee_fee_ratio }}%的担保费:
            本担保费最终解释权归易可易平台）
          </div>
          <div class="yedJs">如您最终退款，该担保费会原路返回</div>
          <div class="yedJs">备注：如您拒绝支付，将不能使用先易额度</div>
        </div>
        <div class="centerDialogVisibleYlian_footer_btnTwo">
          <el-button
            @click="yilianQuxiao"
            type="primary"
            style="
              width: 178px;
              height: 48px;
              background: rgba(0, 82, 217, 0.12);
              border-radius: 90px 90px 90px 90px;
              opacity: 1;
              font-size: 16px;
              font-family: PingFang SC-Medium, PingFang SC;
              font-weight: 500;
              color: #2487e8;
              border: none;
            "
            round
            >取消</el-button
          >
          <el-button
            @click="onPay"
            type="primary"
            style="
              width: 178px;
              height: 48px;
              background: #e84026;
              border-radius: 90px 90px 90px 90px;
              opacity: 1;
              font-size: 16px;
              font-family: PingFang SC-Medium, PingFang SC;
              font-weight: 500;
              color: #fcfcfd;
              border: none;
            "
            round
            >立即支付</el-button
          >
        </div>
      </div>

      <div class="centerDialogVisibleYlian_footer" v-else>
        <div class="centerDialogVisibleYlian_footer_btn">
          本次易定花费 {{ payMoney }} 先易额度
        </div>
        <div class="centerDialogVisibleYlian_footer_btnTwo">
          您的先易额度不足，无法易定，请充值
        </div>
        <div class="centerDialogVisibleYlian_footer_btnTwo">
          <el-button
            @click="yilianzhiNone"
            type="primary"
            style="
              width: 178px;
              height: 48px;
              background: #2487e8;
              border-radius: 90px 90px 90px 90px;
              opacity: 1;
            "
            round
            >知道了</el-button
          >
        </div>
      </div>
    </el-dialog>
    <!-- 易链担保 -->
    <el-dialog
      v-model="centerDialogVisibleDanbao"
      title="您已联系过担保公司，请耐心等待。"
      width="40%"
      align-center
      center
      class="el_ydDialog"
    >
      <div class="centerDialogVisibleYlian_footer">
        <div class="centerDialogVisibleYlian_footer_danbao">
          小提示:您点击“确定联系”后，担保公司会与您联系，进行资信评估，资信评估通过后，担保公司会为您拨发相应的先易额度，您可使用先易额度易定别人的商品。
        </div>
        <div class="centerDialogVisibleYlian_footer_btnTwo">
          <el-button
            @click="danbaoEnding"
            type="primary"
            style="
              width: 490px;
              height: 48px;
              background: #2487e8;
              border-radius: 90px 90px 90px 90px;
              opacity: 1;
            "
            round
            >知道了</el-button
          >
        </div>
      </div>
    </el-dialog>
  </div>
</template>


<script setup>
import { ref, computed, onMounted, watch, inject } from "vue";
import { useRouter } from "vue-router";
import EnterpriseCenterTitle from "@/components/EnterpriseCenterTitle.vue";
import TablePagination from "@/components/TablePagination.vue";
import Empty from "@/components/Empty.vue";
import bgcImg from "../../../assets/images/bgc.png";
import xiajia from "../../../assets/images/xiajia.png";
import {
  CartIndex,
  ByChainMoney,
  CartDelete,
  SetQuantity,
  OrderCreate,
  OrderFeeRatio,
} from "@/api/barterhall";
import { ElMessage } from "element-plus";
import { CompanyInfo } from "@/api/login";
import { useRoute } from "vue-router";

const route = useRoute();
const router = useRouter();
const count = ref(1);
const titleList = ref([
  {
    name: "购物车",
    value: "",
  },
]);

//获取购物车列表

onMounted(() => {
  //选择地址后拿到地址
  if (route.query.addressId) {
    console.log("111", route.query.addressId);
    OrderCreateInfo.value.address_id = route.query.addressId;
  }
  // chooseAddress.value = JSON.parse(localStorage.getItem("cartaddressChoose"));
  // let buyAddress = JSON.parse(localStorage.getItem("cartaddressChoose"));
  // console.log("buyAddress", buyAddress);
  // if (buyAddress != null) {
  //   OrderCreateInfo.value.address_id = buyAddress.id;
  // }

  // console.log("chooseAddress.value", chooseAddress.value);
  getCartIndex();
  getCompanyInfo();
  //获取费率信息
  getOrderFeeRatio();
});
const cartIndexPage = ref({
  page: 1,
  page_size: 10,
});
const getCartIndex = () => {
  CartIndex(cartIndexPage.value)
    .then((res) => {
      if (res.code == 1) {
        cartList.value = res.data.data;
        totalList.value=res.data.total
        console.log("111111", res.data.data);
      }
    })
    .catch((err) => {});
};

const guarantee_fee_ratio = ref(""); //担保手续费率（%）
const transaction_fee_ratio = ref(""); //卖家付款手续费率（%）
//获取费率信息
const getOrderFeeRatio = () => {
  OrderFeeRatio().then((res) => {
    if (res.code == 1) {
      guarantee_fee_ratio.value = res.data.guarantee_fee_ratio;
      transaction_fee_ratio.value = res.data.transaction_fee_ratio;
    }
    if (res.code == 0) {
      ElMessage({ message: res.msg, type: "error" });
    }
  });
};

const CompanyType = ref("");
//支付地址选择
const chooseAddress = ref(null);
//查看公司信息是否有额度
const payMoney = ref(0);
const guarantee_money = ref(0); //先易额度
const available_money = ref(0); //可用先易额度
const chain_money = ref(0); //易链值
const getCompanyInfo = () => {
  CompanyInfo().then((res) => {
    console.log("res.data", res.data);
    guarantee_money.value = res.data.guarantee_money;
    available_money.value = res.data.available_money;
    chain_money.value = res.data.chain_money;
    CompanyType.value = res.data.type;
  });
};

//购物车数据
const cartList = ref([]);
//最小起换量
const num = ref(10);

//
const checkAll = ref(false);
const isIndeterminate = ref(true);
const checkedCities = ref([]);
// const cities = ["Shanghai", "Beijing", "Guangzhou", "Shenzhen"];
const arrList = ref([]);
//全选价格
const allClick = ref(false);
//全选的时候判断是否有下架商品
const findis_canceled = ref({});
const handleCheckAllChange = (val) => {
  // const findCanceled = cartList.value.find(
  //   (cartList) => cartList.is_canceled == "2"
  // );
  // findis_canceled.value = findCanceled;

  // console.log("返回", findCanceled);
  // if (findis_canceled.value.is_canceled) {
  //   return ElMessage({ message: "请删除已下架商品再进行易定", type: "error" });
  // }
  checkedCities.value = [];

  arrList.value = [];
  console.log("val", val);
  cartList.value.forEach((item) => {
    arrList.value.push(item.id);
  });
  OrderCreateInfo.value.cart_ids = arrList.value.join(",");
  console.log("OrderCreateInfo.value.cart_ids", OrderCreateInfo.value.cart_ids);
  ids.value = arrList.value.join(",");
  checkedCities.value = val ? arrList.value : [];
  checkAll.value = val;
  isIndeterminate.value = false;

  console.log("sfgjdkgvjswg", checkedCities.value); //
  if (val === false) {
    cartListTotalPrice.value = 0;
    return;
  }
  cartListTotalPrice.value = 0;
  const doubleCount = computed(() => {
    console.log("cartList.value", cartList.value);
    return cartList.value.map((item) => {
      return (cartListTotalPrice.value +=
        Number(item.price) * Number(item.quantity));
    });
  });
  console.log(doubleCount.value); // 输出：最终价格
  payMoney.value = doubleCount.value[doubleCount.value.length - 1];
};
//全部删除
const allCartListDelete = () => {
  if (ids.value == "" && checkAll.value != true) {
    ElMessage({ message: "请勾选相对应商品，再删除", type: "warning" });
    return;
  }
  deleteCartInfo(ids.value);
};
const ids = ref("");
const cartListTotalPrice = ref(0);
//用于来接的数组 单选
const cartChecked = ref([]);
const buyId = ref("");
//用来结算的数据
const buyGoodsList = ref([]);
const handleCheckedCitiesChange = (value) => {
  ids.value = value.join(",");
  console.log("ids", ids.value);
  OrderCreateInfo.value.cart_ids = value.join(",");
  //控制易定是否相同
  buyId.value = value;
  cartChecked.value = value;
  const checkedCount = value.length; //4
  // checkAll.value = checkedCount === cartList.length;
  if (checkedCount === arrList.value.length) {
    checkAll.value = true;
    isIndeterminate.value = false;
  } else {
    checkAll.value = false;
    isIndeterminate.value = true;
  }
  // isIndeterminate.value =
  //   checkedCount > 0 && checkedCount < arrList.value.length;
  //过滤出相同数据
  cartListTotalPrice.value = 0;
  //需要支付的钱
  //将内容清空
  buyGoodsList.value = [];
  const doubleCount = computed(() => {
    return cartList.value
      .filter((item) => value.includes(item.id))
      .map((item) => {
        console.log("ewefwefew", item);

        buyGoodsList.value.push(item);
        console.log("buyGoodsList", buyGoodsList.value);
        return (cartListTotalPrice.value +=
          Number(item.price) * Number(item.quantity));
      });
  });
  //单选时候 传的总数据

  console.log(doubleCount.value); // 输出：最终价格
  payMoney.value = doubleCount.value[doubleCount.value.length - 1];
};
const onClick = (event) => {
  console.log("Div clicked", event);
};
//改变购物车数量
const handleChange = (value, item) => {
  // stopPropagation();
  let setQuantityInfo = {
    id: item.id,
    quantity: value,
  };
  SetQuantity(setQuantityInfo).then((res) => {
    if (res.code == 1) {
      
      ElMessage({ message: "商品数量修改成功,请重新购买", type: "success" });
      setTimeout(() => {
        location.reload();
      }, 500); // 5000毫秒，即5秒
      
      
      // handleCheckedCitiesChange(cartChecked.value);
    }
  });

  // console.log("value", value, item);
  // item.componyNum = value;
  // item.totalPrice = item.componyNum * item.componyPrice;
  // console.log("list", cartChecked.value);
  // handleCheckedCitiesChange(cartChecked.value);
  // if (checkedCities.value.length == arrList.value.length) {
  //   handleCheckAllChange(true);
  // }
  // // allClick
  // console.log("全选", cartChecked.value);
  // console.log("刷新数据", cartList.value);
};
//删除
const reload = inject("reload");
// const updateFun = () => {
//   reload();
// };
const isdeleteFlag = ref(0);
const deleteCartInfo = async (id) => {
  CartDelete({ ids: id }).then((res) => {
    if (res.code == 1) {
      ElMessage({ message: res.msg, type: "success" });
      isdeleteFlag.value == 1;
      getCartIndex();
      setTimeout(() => {
        location.reload();
      }, 500); 
      // location.reload();
      // reload();
    }
  });
  // let deleteIdArr = [
  //   {
  //     id: id,
  //   },
  // ];
  // const newCartList = cartList.value.filter(
  //   (item) => !deleteIdArr.some((ele) => ele.id == item.id)
  // );
  // console.log("删除", id, deleteIdArr);
  // console.log("新数组", newCartList);
  // cartList.value = newCartList;
  // //改变勾选状态 重新计算
  // const newCartId = ref([]);
  // newCartList.forEach((item) => {
  //   newCartId.value.push(item.id);
  // });
  // console.log("新的id", newCartId.value);
  // handleCheckedCitiesChange(newCartId.value);
};

const OrderCreateInfo = ref({
  source: "2", // 下单来源：1商品详情，2购物车
  goods_spec_id: "", //商品规格ID（商品详情页下单）
  quantity: "", //下单数量（商品详情页下单）
  cart_ids: "", //购物车ID集
  address_id: "", //下单地址ID（线上商品下单均要传）
});

//立即易定
const centerDialogVisible = ref(false);
//订单支付成功的订单id 和支付钱
const orderPay = ref({
  id: "",
  money: "",
});
const buyImmediately = (item) => {
  // OrderCreateInfo.value.address_id = "";
  if (item.type == 1) {
    if (OrderCreateInfo.value.address_id == "") {
      ElMessage({
        message: "您是线上企业，请选择发货地址，再进行易顶",
        type: "warning",
      });
      // router.push("/select-address");
      router.push({
        path: "/select-address",
        query: {
          isFlag: 2,
        },
      });
      return;
    }
  }

  if (item.is_canceled == 2) {
    ElMessage({
      message: "该商品已下架,请删除后易定别的商品",
      type: "warning",
    });
    return;
  }
  console.log("item", item);
  console.log("buyId.value", buyId.value);
  const isExist = buyId.value.includes(item.id);
  if (checkAll.value == true) {
    ElMessage({ message: "全选状态下请一起结算", type: "warning" });
  } else {
    if (buyId.value.length > 1) {
      ElMessage({ message: "多个商品请一起结算", type: "warning" });
    } else {
      if (isExist) {
        OrderCreateInfo.value.cart_ids = item.id;
        OrderCreateInfo.value.quantity = item.quantity;
        //先走订单 再弹框
        OrderCreate(OrderCreateInfo.value).then((res) => {
          OrderCreateInfo.value.address_id = "";
          if (res.code == 1) {
            console.log("易定", res.data);
            ElMessage({
              message: "下单成功请进行支付",
              type: "success",
            });
            centerDialogVisible.value = true;
            //下单成功的id以及价格都返回来了
            orderPay.value.id = res.data.id;
            orderPay.value.money = res.data.money;
            // OrderCreateInfo.value.address_id = "";
            window.localStorage.removeItem("cartaddressChoose");
          }
          if (res.code == 0) {
            ElMessage({
              message: res.msg,
              type: "warning",
            });
          }
        });
      } else {
        ElMessage({ message: "请选择对应商品再进行易定", type: "warning" });
      }
    }
  }
};

//易联值支付
//易链值支付
const YLbuy = () => {
  ByChainMoney({ order_id: orderPay.value.id }).then((res) => {
    if (res.code == 1) {
      ElMessage({
        message: res.msg,
        type: "success",
      });
      yEDuDialogVisible.value = false;
      centerDialogVisible.value = false;
    }
    if (res.code == 0) {
      ElMessage({
        message: res.msg,
        type: "error",
      });
      yEDuDialogVisible.value = false;
      centerDialogVisible.value = false;
    }
  });
};

// 支付宝微信支付
const onPay = (row) => {
  router.push({
    path: "/pay",
    query: {
      id: orderPay.value.id,
      money: orderPay.value.money,
      premiumrate: transaction_fee_ratio.value, //付款手续费用
      type: 2,
      return_url: "/my-easy",
      platform: "end",
    },
  });
};

//结算
const is_canceledBuy = ref(2);
const buyGoods = () => {
  // if (checkAll.value == true) {
  //     //全选结算和单选结算

  //     cartList.value.forEach((item,index)=>{
  //        console.log('oytem',item);
  //      })
  //   // console.log("checkAll.value", checkAll.value);
  //   // centerDialogVisible.value = true;
  //   return;
  // }
  //单选
  // cartChecked.value
  // cartList.value.forEach((item, index) => {
  //   if (is_canceledBuy.value == item.is_canceled) {

  //   }
  // });
  // if (buyId.value.length == 0) {
  //   ElMessage({ message: "请至少选择一个商品再进行易定", type: "warning" });
  //   return;
  // }
  //单选一起结算
  buyGoodsList.value.forEach((item) => {
    if (item.is_canceled == 2) {
      ElMessage({
        message: "您结算的商品中有已下架商品,请删除后再进行结算",
        type: "warning",
      });
      return;
    }
  });
  // for (let i = 0; i < buyGoodsList.value.length - 1; i++) {
  //   if (buyGoodsList.value[i].type != buyGoodsList.value[i + 1].type) {
  //     ElMessage({
  //       message: "不同企业的商品不能一起结算",
  //       type: "warning",
  //     });
  //     return;
  //   }
  // }

  //全选一起结算
  cartList.value.forEach((item) => {
    if (item.is_canceled == 2) {
      ElMessage({
        message: "您结算的商品中有已下架商品,请删除后再进行结算",
        type: "warning",
      });
      return;
    }
  });

  // for (let i = 0; i < cartList.value.length - 1; i++) {
  //   if (cartList.value[i].type != cartList.value[i + 1].type) {
  //     ElMessage({
  //       message: "不同企业的商品不能一起结算",
  //       type: "warning",
  //     });
  //     return;
  //   }
  // }
  if (checkedCities.value.length == 0) {
    ElMessage({
      message: "请至少选择一个商品再进行易定",
      type: "warning",
    });
    return;
  }
  if (OrderCreateInfo.value.address_id == "") {
    ElMessage({
      message: "您是线上企业，请选择发货地址，再进行易顶",
      type: "warning",
    });
    // router.push("/select-address");
    router.push({
      path: "/select-address",
      query: {
        isFlag: 2,
      },
    });
    return;
  }
  //先走订单 再弹框
  OrderCreate(OrderCreateInfo.value).then((res) => {
    if (res.code == 1) {
      console.log("易定", res.data);
      OrderCreateInfo.value.address_id = "";
      ElMessage({
        message: "下单成功请进行支付",
        type: "success",
      });
      centerDialogVisible.value = true;
      //下单成功的id以及价格都返回来了
      orderPay.value.id = res.data.id;
      orderPay.value.money = res.data.money;
      // OrderCreateInfo.value.address_id = "";
      // window.localStorage.removeItem("cartaddressChoose");
    }
    if (res.code == 0) {
      ElMessage({
        message: res.msg,
        type: "warning",
      });
    }
  });
};
const yilianzhi = ref(977); //拥有的
const yilianzhiOrder = ref(900); //购买所需的
//使用易链值购买
const centerDialogVisibleYlian = ref(false);
const onBuyCenterDialogVisible = () => {
  if (chain_money.value == 0.0) {
    ElMessage({
      message:
        "您还没有易链值，请先发布自己的商品，别人购买后会给您相应的易链值哦",
      type: "warning",
    });
  } else {
    yEDuDialogVisible.value = true;
  }
};
const yEDuDialogVisible = ref(false);
//使用先易额度购买
const yiEDuBuyCenterDialogVisible = () => {
  centerDialogVisibleYlian.value = true;
};
//易链值是否交易
const yilianQuxiao = () => {
  centerDialogVisibleYlian.value = false;
};
//易链值不够关闭弹框
const yilianzhiNone = () => {
  centerDialogVisibleYlian.value = false;
};
//没有易链值 担保
const danbaoJe = ref(0);
//确认联系担保
const centerDialogVisibleDanbao = ref(false);
const onQueRen = () => {
  centerDialogVisibleDanbao.value = true;
  centerDialogVisibleYlian.value = false;
  centerDialogVisible.value = false;
};
const danbaoEnding = () => {
  centerDialogVisibleDanbao.value = false;
};
// 数据总条数
const totalList = ref(0);
const handleCurrentChange = (val) => {
  cartIndexPage.value.page = val;
  getCartIndex();
};
</script>

<style lang="less" scoped>
.buyOnce {
  border-radius: 8px 8px 8px 8px;
  font-size: 14px;
  font-family: PingFang SC-Medium, PingFang SC;
  font-weight: 500;
  color: #ffffff;
  opacity: 1;
  width: 80px;
  height: 42px;
  line-height: 42px;
  background: #2487e8;
  border-radius: 8px 8px 8px 8px;
  opacity: 1;
  text-align: center;
  margin-left: 15px;
  margin-right: 5px;
}
.onbuyOnce {
  border-radius: 8px 8px 8px 8px;
  font-size: 14px;
  font-family: PingFang SC-Medium, PingFang SC;
  font-weight: 500;
  color: #ffffff;
  opacity: 1;
  width: 80px;
  height: 42px;
  line-height: 42px;
  border-radius: 8px 8px 8px 8px;
  opacity: 1;
  text-align: center;
  margin-left: 15px;
  margin-right: 5px;
  background: #C0C4CC;
}
.shoppingCart {
  :deep(.el-dialog) {
    border-radius: 16px 16px 16px 16px;
  }
  .container {
    height: calc(100vh - 204px);
  }
}
.noneCartList {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 500px;
  width: 100%;
  // border: 1px solid red;
  span {
    display: inline-block;
    font-size: 24px;
    font-family: PingFang SC-Bold, PingFang SC;
    font-weight: bold;
    color: rgba(0, 0, 0, 0.87);
  }
}
.enterprise-center {
  color: #888;
}
.centerDialogVisibleYlian_footer {
  display: flex;
  flex-direction: column;
  align-items: center;
  .centerDialogVisibleYlian_footer_yed {
    height: 48px;
    font-size: 23px;
    font-family: PingFang SC-Bold, PingFang SC;
    font-weight: bold;
    color: #141416;
    line-height: 48px;
  }
  .centerDialogVisibleYlian_footer_danbao {
    font-size: 16px;
    font-family: PingFang SC-Medium, PingFang SC;
    font-weight: 500;
    color: #18bc9f;
    margin: 32px 0;
    .yedJs {
      font-size: 20px;
      font-family: PingFang SC-Medium, PingFang SC;
      font-weight: 500;
      color: rgba(0, 0, 0, 0.87);
      line-height: 40px;
    }
  }
  .centerDialogVisibleYlian_footer_hetong {
    display: flex;
    align-items: center;
    span {
      font-size: 16px;
      font-family: PingFang SC-Medium, PingFang SC;
      font-weight: 500;
      color: #2487e8;
      width: 100%;
    }
  }
  .centerDialogVisibleYlian_footer_btn {
    height: 48px;
    font-size: 23px;
    font-family: PingFang SC-Bold, PingFang SC;
    font-weight: bold;
    color: #141416;
    line-height: 48px;
  }
  .centerDialogVisibleYlian_footer_btnTwo {
    height: 48px;
    font-size: 23px;
    font-family: PingFang SC-Bold, PingFang SC;
    font-weight: bold;
    color: #141416;
    line-height: 48px;
    margin-top: 20px;
  }
}
.centerDialogVisible_footer {
  //   border: 1px solid red;
  display: flex;
  flex-direction: column;
  align-items: center;
  .tittle {
    height: 48px;
    font-size: 23px;
    font-family: PingFang SC-Bold, PingFang SC;
    font-weight: bold;
    color: #141416;
    line-height: 48px;
    margin-bottom: 32px;
  }
  .centerDialogVisible_footer_btn {
    width: 372px;
    height: 114px;
    background: #2487e8;
    border-radius: 12px 12px 12px 12px;
    opacity: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    font-family: DIN-Bold, DIN;
    font-weight: bold;
    color: #ffffff;
    // cursor: pointer;
    margin-bottom: 30px;
  }
  .centerDialogVisible_footer_btnTwo {
    width: 372px;
    height: 114px;
    background: #d9d9d9;
    border-radius: 12px 12px 12px 12px;
    opacity: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    // margin-top: 32px;
    font-size: 28px;
    font-family: DIN-Bold, DIN;
    font-weight: bold;
    color: #ffffff;
    margin-bottom: 30px;
    // cursor: pointer;
  }
}
.shoppingCart {
  // border: 1px solid red;
  box-sizing: border-box;
  padding: 0px 16px;
  .carr_num {
    height: 46px;
    background: #f5f5f5;
    border-radius: 8px 8px 8px 8px;
    opacity: 1;
    font-size: 18px;
    font-family: PingFang SC-Bold, PingFang SC;
    font-weight: bold;
    color: rgba(0, 0, 0, 0.87);
    box-sizing: border-box;
    padding: 12px;
    text-align: left;
  }
  .cart_list {
    // border: 1px solid red;
    margin-top: 20px;
    .el_checkbox_group {
      // border: 1px solid green;
      display: flex;
      flex-direction: column;
      .el_checkbox {
        height: 192px;
        border-radius: 0px 0px 0px 0px;
        opacity: 1;
        // border: 1px solid #e6e6e6;
        margin: 10px 0;
        .cartList_info {
          box-sizing: border-box;
          height: 192px;
          border-radius: 0px 0px 0px 0px;
          opacity: 1;
          border: 1px solid #e6e6e6;
          margin: 10px 0;
          box-sizing: border-box;
          padding: 12px 4px 12px 12px;
          display: flex;
          flex-direction: column;
          // width: 100%;
          .cartList_info_tittle {
            height: 46px;
            background: #f5f5f5;
            border-radius: 8px 8px 8px 8px;
            opacity: 1;
            font-size: 16px;
            font-family: PingFang SC-Bold, PingFang SC;
            font-weight: bold;
            color: rgba(0, 0, 0, 0.87);
            text-align: left;
            line-height: 46px;
            padding-left: 15px;
            box-sizing: border-box;
            width: 933px;
            /* 固定宽度 */
            text-overflow: ellipsis;
            -o-text-overflow: ellipsis;
            overflow: hidden;
            white-space: nowrap;
          }
          .cartList_info_list {
            // border: 1px solid green;
            margin-top: 15px;
            display: flex;
            // align-items: center;
            // width: 100%;
            // width: 948px;
            .cart_img {
              position: relative;
              width: 126px;
              height: 98px;
              border-radius: 10px 10px 10px 10px;
              opacity: 1;
              img {
                border-radius: 10px 10px 10px 10px;
                height: 100%;
                width: 100%;
              }
              .xiajia {
                position: absolute;
                width: 48px;
                height: 48px;
                left: 0px;
                top: 0px;
              }
            }
            .cart_info_content {
              flex: 1;
              display: flex;
              box-sizing: border-box;
              .cart_info_content_tittle {
                display: flex;
                flex-direction: column;
                width: 250px;
                padding-left: 10px;
                .tittle {
                  font-size: 16px;
                  font-family: PingFang SC-Medium, PingFang SC;
                  font-weight: 500;
                  color: rgba(0, 0, 0, 0.87);
                  height: 64px;
                  overflow: hidden;
                  text-overflow: ellipsis;
                  display: -webkit-box;
                  -webkit-line-clamp: 2; //行数
                  -webkit-box-orient: vertical;
                }
                span {
                  font-size: 16px;
                  font-family: PingFang SC-Medium, PingFang SC;
                  font-weight: 500;
                  color: rgba(0, 0, 0, 0.87);
                }
              }
              .cart_info_content_pruice {
                display: flex;
                flex-direction: column;
                width: 25%;
                width: 180px;

                align-items: center;
                span {
                  font-size: 16px;
                  font-family: PingFang SC-Medium, PingFang SC;
                  font-weight: 500;
                  color: rgba(0, 0, 0, 0.87);
                }
              }
              .cart_info_content_num {
                display: flex;
                flex-direction: column;
                width: 35%;
                width: 150px;

                align-items: center;
                span {
                  font-size: 16px;
                  font-family: PingFang SC-Medium, PingFang SC;
                  font-weight: 500;
                  color: rgba(0, 0, 0, 0.87);
                }
              }
            }
            .cart_button {
              width: 220px;
              display: flex;
              align-items: center;
              justify-content: flex-end;
            }
          }
        }
      }
    }
  }
  .carr_numBuy {
    height: 74px;
    border-radius: 0px 0px 0px 0px;
    opacity: 1;
    border: 1px solid #e6e6e6;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    box-sizing: border-box;
    padding: 5px;
    .all_money {
      font-size: 20px;
      font-family: PingFang SC-Bold, PingFang SC;
      font-weight: bold;
      color: rgba(0, 0, 0, 0.87);
      margin-right: 16px;
    }
  }
}
</style>
